import java.util.Deque;
import java.util.LinkedList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-05-28
 * Time: 10:00
 */
public class TestHeap {
    public int[] elem;
    public int usedSize;
    public TestHeap(){
        this.elem = new int[10];
    }

    public void createHeap(int[] array){
        for(int i =0;i<array.length;++i){
            this.elem[i] = array[i];
            usedSize++;
        }
        for(int p = (this.usedSize-1-1)/2;p>=0;p--){
            shiftDown(p,this.usedSize);
        }
    }
    private void swap(int[] elem,int i,int j){
        int tmp = this.elem[i];
        this.elem[i] = this.elem[j];
        this.elem[j] = tmp;
    }
    public void shiftDown(int root,int len){
       int parent = root;
       int child = 2*parent+1;
       while(child<len){
           //选出两个孩子节点的最大值
           if(child+1<len&&this.elem[child]<elem[child+1]){
               child++;
           }
           if(this.elem[parent]<this.elem[child]) {
               swap(this.elem, child, parent);
               parent = child;
               child = 2*parent+1;
           }else {
                  //不需要调整
               break;
           }
       }

    }

    public static void main(String[] args) {


    }


}
